package com.inei.evaluaciondelaencuesta.tools;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.inei.evaluaciondelaencuesta.R;

import android.content.Context;
import android.widget.SimpleAdapter;
import android.widget.Spinner;

public class SpinnerUtil {

	Context context;

	public SpinnerUtil(Context context) {
		this.context = context;
	}

	public void spinnerLECTURA(Spinner... sp) {
		SimpleAdapter adapter = new SimpleAdapter(context,
				LISTA(R.array.LECTURA), R.layout.spinner_item,
				new String[] { "texto" }, new int[] { R.id.tvItem });
		for (int i = 0; i < sp.length; i++) {
			sp[i].setAdapter(adapter);
		}
	}

	public void spinnerCOMPRENSION(Spinner... sp) {
		SimpleAdapter adapter = new SimpleAdapter(context,
				LISTA(R.array.COMPRENSION), R.layout.spinner_item,
				new String[] { "texto" }, new int[] { R.id.tvItem });
		for (int i = 0; i < sp.length; i++) {
			sp[i].setAdapter(adapter);
		}
	}
	
	public void spinnerOTROS(Spinner... sp) {
		SimpleAdapter adapter = new SimpleAdapter(context,
				LISTA(R.array.OTROS), R.layout.spinner_item,
				new String[] { "texto" }, new int[] { R.id.tvItem });
		for (int i = 0; i < sp.length; i++) {
			sp[i].setAdapter(adapter);
		}
	}
	
	public void spinnerERRORES(Spinner... sp) {
		SimpleAdapter adapter = new SimpleAdapter(context,
				LISTA(R.array.ERRORES), R.layout.spinner_item,
				new String[] { "texto" }, new int[] { R.id.tvItem });
		for (int i = 0; i < sp.length; i++) {
			sp[i].setAdapter(adapter);
		}
	}
	
	public List<HashMap<String, String>> LISTA(int recurso) {
		List<HashMap<String, String>> lista = new ArrayList<HashMap<String, String>>();
		String[] lectura = context.getResources().getStringArray(recurso);
		for (int i = 0; i < lectura.length; i++) {
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("texto", lectura[i]);
			lista.add(map);
		}
		return lista;
	}
}
